package element.base;

import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import element.synt.BType;
import element.synt.BlockItem;
import element.synt.Decl;
import intermediate_representation.InterRP;

import java.util.ArrayList;

public class Synt extends TreeNode {
//    private Nontertype type;
    private ArrayList<TreeNode> nodes;

    public Synt() {
        this.nodes = new ArrayList<>();
    }

    public void addNode(TreeNode node) {
        this.nodes.add(node);
    }

    public ArrayList<TreeNode> getNodes() {
        return nodes;
    }

    public int getLindex() {
        return nodes.get(nodes.size() - 1).getLindex();
    }

    public boolean isType(Class type) {
        return (this.getClass().equals(type));
    }

    public Word findFirst() {
        TreeNode node = nodes.get(0);
        if (node instanceof Word) {
            return (Word) node;
        } else {
            return ((Synt) node).findFirst();
        }
    }

    public void tointerRP() {
    }

    @Override
    public String toString() {
        String fstr = "";
        for (TreeNode node: nodes) {
            fstr += node.toString() + "\n";
        }
        if (!(this instanceof BlockItem) && !(this instanceof Decl) && !(this instanceof BType)) {
            fstr += "<" + this.getClass().getSimpleName() + ">";
        }
        if (fstr.charAt(fstr.length() - 1) == '\n') {
            fstr = fstr.substring(0, fstr.length() - 1);
        }
        return fstr;
    }
}
